<template>
  <div>
    <div>
      <el-button type="success" icon="el-icon-plus" @click="handleAdd()"
        >新增活动</el-button
      >
      <el-button type="primary" icon="el-icon-plus" @click="handleCode()"
        >生成赠品活动条形码</el-button
      >
    </div>

    <el-dialog
      title="新增活动"
      :visible.sync="addFormVisible"
      :close-on-click-modal="false"
      @close="handleAddCancel()"
      width="35%"
    >
      <el-form
        :model="addForm"
        :rules="discountRules"
        ref="addForm"
        label-position="left"
        label-width="80px"
      >
        <el-form-item label="活动名称" prop="discountName">
          <el-input
            v-model="addForm.discountName"
            maxlength="20"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="活动类型" prop="discountSort">
          <el-select v-model="addForm.discountSort" placeholder="请选择">
            <el-option
              v-for="item in sortOptions"
              :key="item.discountSortNumber"
              :label="item.discountSortName"
              :value="item.discountSortNumber"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="折扣率" v-show="isDiscount" prop="discountRate">
          <el-input
            placeholder="0~100"
            v-model.number="addForm.discountRate"
            maxlength="3"
            style="width: 200px"
            ><template slot="prepend">-</template
            ><template slot="append">%</template></el-input
          >
        </el-form-item>
        <el-form-item label="持续时间" prop="discountTime">
          <el-date-picker
            v-model="addForm.discountTime"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="pickerOptions"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="discountDescr">
          <el-input
            type="textarea"
            v-model="addForm.discountDescr"
            maxlength="100"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="活动状态" prop="discountState">
          <el-radio-group v-model="addForm.discountState">
            <el-radio :label="1">开启</el-radio>
            <el-radio :label="0">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleAddCancel()">取 消</el-button>
        <el-button type="primary" @click="submitAddForm('addForm')"
          >确 定</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      title="编辑活动"
      :visible.sync="editFormVisible"
      :close-on-click-modal="false"
      @close="handleEditCancel()"
      width="35%"
    >
      <el-form
        :model="editForm"
        :rules="discountRules"
        ref="editForm"
        label-position="left"
        label-width="80px"
      >
        <el-form-item label="活动名称" prop="Discount_name">
          <el-input
            v-model="editForm.Discount_name"
            maxlength="20"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="活动类型" prop="Discount_sort">
          <el-select v-model="editForm.Discount_sort" placeholder="请选择">
            <el-option
              v-for="item in sortOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="折扣率" v-show="isDiscount" prop="discountRate">
          <el-input
            placeholder="0~100"
            v-model.number="editForm.discountRate"
            maxlength="3"
            style="width: 200px"
            ><template slot="prepend">-</template
            ><template slot="append">%</template></el-input
          >
        </el-form-item>
        <el-form-item label="持续时间" prop="discountTime">
          <el-date-picker
            v-model="editForm.discountTime"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="discountDescr">
          <el-input
            type="textarea"
            v-model="editForm.discountDescr"
            maxlength="100"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="活动状态" prop="discountState">
          <el-radio-group v-model="editForm.discountState">
            <el-radio :label="1">开启</el-radio>
            <el-radio :label="0">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleEditCancel()">取 消</el-button>
        <el-button type="primary" @click="submitEditForm('editForm')"
          >确 定</el-button
        >
      </div>
    </el-dialog>

    <el-dialog
      title="生成条形码"
      :visible.sync="codeFormVisible"
      :close-on-click-modal="false"
      @close="handleCodeCancel()"
      width="35%"
      ><el-select v-model="codeForm.Discount_name" placeholder="请选择">
        <el-option
          v-for="item in tableData"
          :key="item.discountNumber"
          :label="item.discountName"
          :value="item.discountName"
        >
        </el-option>
      </el-select>
      <el-button
        type="success"
        @click="handleGeneration()"
        style="margin-left: 15px"
        >生成</el-button
      >
      <div id="codeArea">条形码区</div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCodeCancel()">取 消</el-button>
        <el-button type="primary" @click="handleCodeConfirm()">确 定</el-button>
      </div>
    </el-dialog>

    <!-- FIXME 详细信息html -->
    <el-dialog title="详细商品信息" :visible.sync="moreFormVisible">
      <el-select
        v-model="classForm.class_first"
        placeholder="一级类别"
        style="margin-left: 15px"
      >
        <el-option
          v-for="(item, index) in classOptions"
          :key="index"
          :label="item.class_first"
          :value="item.class_first"
        >
        </el-option>
      </el-select>
      <el-select
        v-model="classForm.class_second"
        placeholder="二级类别"
        style="margin-left: 15px"
      >
        <el-option
          v-for="(item, index) in classOptions"
          :key="index"
          :label="item.class_second"
          :value="item.class_second"
        >
        </el-option>
      </el-select>
      <el-button type="success" @click="selectGoods" style="margin-left: 15px"
        >查询商品</el-button
      >
      <el-table :data="goodsInfo" height="309">
        <el-table-column prop="id" label="商品ID"> </el-table-column>
        <el-table-column prop="barcode" label="条形码"> </el-table-column>
        <el-table-column prop="goodsName" label="商品名称"> </el-table-column>
        <el-table-column prop="goodsNumber" label="商品数量">
          <!-- <template slot-scope="scope">
            <el-input-number
              v-model="scope.row.goodsNumber"
              :min="0"
              :max="scope.row.quantityInStock"
              label="商品数量"
            ></el-input-number>
          </template> -->
        </el-table-column>
        <el-table-column label="操作" >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="handleGoodsDelete(scope.$index, scope.row)"
              icon="el-icon-delete"
              >删除</el-button
            >
            <el-button
              size="mini"
              @click="handleGoodsChange(scope.row)"
              icon="el-icon-delete"
              >修改数量</el-button
            >
          </template></el-table-column
        >
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleMoreCancel()">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- FIXME 抽屉html -->
    <el-drawer
      title="我是标题"
      :visible.sync="drawerVisible"
      direction="rtl"
      size="50%"
      :before-close="handleDrawerCancel"
    >
      <el-table
        :data="drawerData"
        tooltip-effect="dark"
        style="width: 100%"
        height="100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="goodsName" label="商品名称"> </el-table-column>
        <el-table-column prop="barcode" label="条形码" width="100">
        </el-table-column>
        <el-table-column prop="persentPrice" label="单价" width="50">
        </el-table-column>
        <el-table-column prop="goodsNumber" label="商品数量">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.goodsNumber"
              size="mini"
              label="商品数量"
            ></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="quantityInStock"
          label="库存"
          show-overflow-tooltip
        >
        </el-table-column>
      </el-table>
    </el-drawer>

    <div id="table">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="discountNumber" label="活动编号">
        </el-table-column>
        <el-table-column prop="discountName" label="活动名称">
        </el-table-column>
        <el-table-column prop="discountSort" label="活动类型">
        </el-table-column>
        <el-table-column
          prop="onTime"
          label="开启时间"
          :formatter="onDateFormat"
        >
        </el-table-column>
        <el-table-column
          prop="offTime"
          label="结束时间"
          :formatter="offDateFormat"
        >
        </el-table-column>
        <el-table-column prop="comment" label="备注"> </el-table-column>
        <el-table-column label="活动状态" width="150">
          <template slot-scope="scope"
            ><el-switch
              v-model="scope.row.discountState"
              :active-value="1"
              :inactive-value="0"
              active-color="#13ce66"
              active-text="开启"
              inactive-text="关闭"
              @change="handleState(scope.row)"
            >
            </el-switch
          ></template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope2">
            <el-button
              size="mini"
              @click="handleMore(scope2.row)"
              icon="el-icon-more-outline"
              >详细</el-button
            >
            <!-- <el-button
              size="mini"
              type="primary"
              @click="handleEdit()"
              icon="el-icon-edit"
              >编辑</el-button
            > -->
            <el-button
              size="mini"
              type="danger"
              @click="handleDiscountDelete(scope2.$index, scope2.row)"
              icon="el-icon-delete"
              >删除</el-button
            >
          </template></el-table-column
        ></el-table
      >
    </div>

    <el-pagination
      background
      :current-page="currentPage"
      layout="total,prev, pager, next"
      :total="total"
      :page-size="pageSize"
      @current-change="pageChange"
    ></el-pagination>
  </div>
</template>
<script>
// import _ from "lodash"
export default {
  name: "cuxiaohuodong-huodong",
  data() {
    var checkRate = (rule, value, callback) => {
      if (this.isDiscount) {
        if (!value) {
          return callback(new Error("折扣不能为空"));
        }
        setTimeout(() => {
          if (!Number.isInteger(value)) {
            callback(new Error("必须为0~100之间的整数值"));
          } else {
            if (value < 0 || value > 100) {
              callback(new Error("必须为0~100之间的整数值"));
            } else {
              callback();
            }
          }
        }, 1000);
      } else {
        callback();
      }
    };
    return {
      total: 100,
      pageSize: 5,
      currentPage: 1,
      activeName: "first",
      classForm: {
        class_first: "",
        class_second: "",
      },
      editForm: {},
      codeForm: {
        Discount_name: "",
      },
      addFormVisible: false,
      moreFormVisible: false,
      moreFormVisible2: false,
      editFormVisible: false,
      codeFormVisible: false,
      drawerVisible: false,
      addForm: {
        discountName: "",
        discountSort: 1,
        discountDescr: "",
        discountState: 0,
        discountRate: "",
        discountTime: [],
      },
      goodsInfo: [],
      goodsInfoTmp: [],
      goodsInfoSend: [],
      discountNumberSend: 0,
      drawerData: [],
      multipleSelection: [],
      tableData: [],
      sortOptions: [],
      classOptions: [],
      pickerOptions: {
        shortcuts: [
          {
            text: "未来7天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "未来30天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "未来90天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              end.setTime(end.getTime() + 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      discountRules: {
        discountName: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
        ],
        discountSort: [
          { required: true, message: "请选择活动类型", trigger: "change" },
        ],
        discountRate: [
          { validator: checkRate, required: false, trigger: "blur" },
        ],
        discountTime: [
          {
            required: true,
            message: "请选择活动持续日期",
            trigger: "change",
          },
        ],
        discountState: [{ required: true, trigger: "change" }],
      },
    };
  },
  methods: {
    handleAdd() {
      //测试用，待删
      // this.goodsInfoSend = [];
      // this.goodsInfo.map((it) => {
      //   this.goodsInfoSend.push(this._.pick(it, "id", "discountNumber", "goodsNumber"));
      // });
      // console.log("goodsInfoSend",this.goodsInfoSend)

      this.$axios({
        url: "/getDstSort",
        method: "get",
      }).then((res) => {
        console.log("类型选项res", res);
        this.sortOptions = res.data.data;
      });
      this.addFormVisible = true;
      // this.$nextTick(() => {
      //   this.$refs["addForm"].resetFields();
      // });
    },
    handleAddConfirm() {
      //FIXME 添加活动
      console.log("发送请求前的userId:", this.userId);
      this.$axios({
        url: "/addDst",
        method: "post",
        data: {
          discountName: this.addForm.discountName,
          discountState: this.addForm.discountState,
          discountSortNumber: this.addForm.discountSort,
          onTime: this.addForm.discountTime[0],
          offTime: this.addForm.discountTime[1],
          comment: this.addForm.discountDescr,
          userId: this.userId + "",
          // discountName: "name4",
          // discountState: 1,
          // discountSortNumber: 2,
          // onTime: 1627488000000,
          // offTime: 1627488000000,
          // comment: "备注",
          // userId: 58,
        },
      }).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$axios({
            url: "/findDstAll",
            method: "get",
            params: {
              page: this.currentPage,
              num: this.pageSize,
            },
          }).then((res) => {
            this.tableData = res.data.data;
          });
          this.$message({
            type: "success",
            message: "添加成功!",
          });
        } else {
          this.$message({
            type: "warning",
            message: "添加失败!",
          });
        }
      });
    },
    handleAddCancel() {
      console.log("点击关闭的addForm", this.addForm);
      this.addFormVisible = false;
    },
    handleEdit() {
      //编辑活动按钮
      // this.editFormVisible = true;
      // this.editForm = Object.assign({}, row);
      this.moreFormVisible2 = true;
    },
    handleEditCancel() {
      //编辑活动表单关闭
      this.editFormVisible = false;
    },
    handleCode() {
      //条形码生成界面
      this.codeForm.Discount_name = "";
      this.codeFormVisible = true;
    },
    handleCodeConfirm() {
      this.codeFormVisible = false;
    },
    handleCodeCancel() {
      this.codeFormVisible = false;
    },
    handleGeneration() {
      //TODO 生成条形码
      //请求axios，得到活动的条形码
      // this.$axios({
      //   url: "/",
      //   method: "",
      // }).then((res) => {
      //   console.log(res);
      //   if (res.data.code == 200) {
      //     this.$message({
      //       type: "success",
      //       message: "保存成功!",
      //     });
      //   } else {
      //     this.$message({
      //       type: "warning",
      //       message: "保存失败!",
      //     });
      //   }
      // });
    },
    handleState(row) {
      this.$axios({
        url: "/changeDstState",
        method: "get",
        params: {
          discount_number: row.discountNumber,
          discount_state: row.discountState,
        },
      }).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$message({
            type: "success",
            message: "修改成功!",
          });
        } else {
          this.$message({
            type: "warning",
            message: "修改失败!",
          });
        }
      });
    },
    handleMore(row) {
      //TODO 查询活动里的商品
      //获得活动编号
      //请求axios，把商品存到goodsInfo
      this.discountNumberSend = row.discountNumber;
      console.log("row", row);
      this.$axios({
        url: "/findDcProducts",
        method: "get",
        params: {
          num: 10000,
          page: 1,
          discount_number: row.discountNumber,
        },
      }).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.goodsInfo = res.data.data;
          // this.goodsInfo.forEach(item => {
          //   item.discountNumber= this.discountNumberSend
          // });
          this.$message({
            type: "success",
            message: "查询成功!",
          });
        } else {
          this.$message({
            type: "warning",
            message: "查询失败!",
          });
        }
      });
      this.moreFormVisible = true;
    },
    handleMoreConfirm() {
      //TODO 添加商品信息
      //请求axios，发送goodsInfoSend
      this.goodsInfoSend = [];
      this.goodsInfo.map((it) => {
        //利用lodash库函数_.pick提取goodsInfo关键字段到goodsInfoSend
        this.goodsInfoSend.push(
          this._.pick(it, "id", "discountNumber", "goodsNumber")
        );
      });
      //goodsInfoSend中每个商品添加活动编号
      this.goodsInfoSend.forEach((item) => {
        item.discountNumber = this.discountNumberSend;
      });
      console.log("this.goodsInfoSend", this.goodsInfoSend);
      this.$axios({
        url: "/addDcProduct",
        method: "post",
        data: this.goodsInfoSend,
      }).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$message({
            type: "success",
            message: "保存成功!",
          });
        } else {
          this.$message({
            type: "warning",
            message: "保存失败!",
          });
        }
      });
      this.moreFormVisible = false;
    },
    handleMoreCancel() {
      //TODO 关闭详细窗口
      this.goodsInfo = [];
      this.moreFormVisible = false;
    },
    handleDiscountDelete(index, row) {
      console.log(index, row);
      this.$confirm("此操作将删除该活动, 是否继续?", "提示", {
        confirmButtonText: "删除",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios({
            url: "/deleteDst",
            method: "get",
            params: { discount_number: row.discountNumber },
          }).then((res) => {
            console.log(res);
            if (res.data.code == 200) {
              this.$axios({
                url: "/findDstAll",
                method: "get",
                params: {
                  page: this.currentPage,
                  num: this.pageSize,
                },
              }).then((res) => {
                console.log("活动res：", res);
                this.tableData = res.data.data;
              });
              this.$message({
                type: "success",
                message: "删除成功!",
              });
            } else {
              this.$message({
                type: "warning",
                message: "删除失败!",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleGoodsDelete() {
      //TODO 删除商品
      this.$axios({
        url: "/deleteDcProduct",
        method: "get",
        params: { id: 127 },
      }).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        } else {
          this.$message({
            type: "warning",
            message: "删除失败!",
          });
        }
      });

      // this.$confirm("此操作将删除该商品, 是否继续?", "提示", {
      //   confirmButtonText: "删除",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(() => {
      //     console.log(row);
      //     // this.goodsInfo.splice(index, 1);
      //     // this.$message({
      //     //   type: "success",
      //     //   message: "删除成功!",
      //     // });
      //     this.$axios({
      //       url: "/deleteDcProduct",
      //       method: "post",
      //       data: { id: 132 },
      //     }).then((res) => {
      //       console.log(res);
      //       if (res.data.code == 200) {
      //         this.$message({
      //           type: "success",
      //           message: "删除成功!",
      //         });
      //       } else {
      //         this.$message({
      //           type: "warning",
      //           message: "删除失败!",
      //         });
      //       }
      //     });
      //   })
      //   .catch(() => {
      //     this.$message({
      //       type: "info",
      //       message: "已取消删除",
      //     });
      //   });
    },
    handleDrawerCancel(done) {
      //FIXME 关闭抽屉
      this.$confirm("是否进行添加？", "确认信息", {
        distinguishCancelAndClose: true,
        confirmButtonText: "添加",
        cancelButtonText: "放弃添加",
      })
        .then(() => {
          this.goodsInfoSend = [];
          this.goodsInfoTmp.map((it) => {
            //利用lodash库函数_.pick提取goodsInfoTmp关键字段到goodsInfoSend
            this.goodsInfoSend.push(
              this._.pick(it, "id", "discountNumber", "goodsNumber")
            );
          });
          //goodsInfoSend中每个商品添加活动编号
          this.goodsInfoSend.forEach((item) => {
            item.discountNumber = this.discountNumberSend;
          });
          console.log("this.goodsInfoSend", this.goodsInfoSend);
          this.$axios({
            url: "/addDcProduct",
            method: "post",
            data: this.goodsInfoSend,
          }).then((res) => {
            console.log(res);
            if (res.data.code == 200) {
              done();
              this.$message({
                type: "success",
                message: "添加成功!",
              });
              this.$axios({
                url: "/findDcProducts",
                method: "get",
                params: {
                  num: 10000,
                  page: 1,
                  discount_number: this.discountNumberSend,
                },
              }).then((res) => {
                console.log(res);
                if (res.data.code == 200) {
                  this.goodsInfo = res.data.data;
                  this.$message({
                    type: "success",
                    message: "查询成功!",
                  });
                } else {
                  this.$message({
                    type: "warning",
                    message: "查询失败!",
                  });
                }
              });
            } else {
              this.$message({
                type: "warning",
                message: "添加失败!",
              });
            }
          });
          // this.goodsInfo = this.goodsInfo.concat(this.goodsInfoTmp);
          // done();
          // this.$message({
          //   type: "info",
          //   message: "保存修改",
          // });
        })
        .catch((action) => {
          if (action === "cancel") {
            done();
            this.$message({
              type: "info",
              message: "放弃保存并离开页面",
            });
          } else {
            this.$message({
              type: "info",
              message: "停留在当前页面",
            });
          }
        });
    },
    handleSelectionChange(val) {
      console.log("val:", val);
      this.goodsInfoTmp = val;
    },
    handleGoodsChange(row) {
      //TODO 修改商品数量
      this.$prompt("请输入数量", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(({ value }) => {
          console.log(row.id, "____", value);
          this.$axios({
            url: "/changeGoodsNumber",
            method: "get",
            params: {
              id: row.id,
              goods_number: value,
            },
          }).then((res) => {
            console.log(res);
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: "修改成功!",
              });
              this.$axios({
                url: "/findDcProducts",
                method: "get",
                params: {
                  num: 10000,
                  page: 1,
                  discount_number: this.discountNumberSend,
                },
              }).then((res) => {
                console.log(res);
                if (res.data.code == 200) {
                  this.goodsInfo = res.data.data;
                  this.$message({
                    type: "success",
                    message: "查询成功!",
                  });
                } else {
                  this.$message({
                    type: "warning",
                    message: "查询失败!",
                  });
                }
              });
            } else {
              this.$message({
                type: "warning",
                message: "修改失败!",
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入",
          });
        });
    },
    submitAddForm(formName) {
      console.log(this.addForm);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.handleAddConfirm();
          this.addFormVisible = false;
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    submitEditForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.tableData[0].On_time = this.editForm.discountTime[0];
          this.tableData[0].Off_time = this.editForm.discountTime[1];
          this.$message({
            message: "修改成功",
            type: "success",
          });
          this.editFormVisible = false;
          console.log("时间：", this.editForm.discountTime);
          console.log("this.tableData[0].On_time:", this.tableData[0].On_time);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    onDateFormat(row) {
      if (row.onTime) {
        var time = new Date(row.onTime);
        var y = time.getFullYear(); //getFullYear方法以四位数字返回年份
        var M = time.getMonth() + 1; // getMonth方法从 Date 对象返回月份 (0 ~ 11)，返回结果需要手动加一
        var d = time.getDate(); // getDate方法从 Date 对象返回一个月中的某一天 (1 ~ 31)
        // var h = time.getHours(); // getHours方法返回 Date 对象的小时 (0 ~ 23)
        // var m = time.getMinutes(); // getMinutes方法返回 Date 对象的分钟 (0 ~ 59)
        // var s = time.getSeconds(); // getSeconds方法返回 Date 对象的秒数 (0 ~ 59)
        return y + "-" + M + "-" + d; // + ' ' + h + ':' + m + ':' + s
      } else {
        return "";
      }
    },
    offDateFormat(row) {
      if (row.offTime) {
        var time = new Date(row.offTime);
        var y = time.getFullYear(); //getFullYear方法以四位数字返回年份
        var M = time.getMonth() + 1; // getMonth方法从 Date 对象返回月份 (0 ~ 11)，返回结果需要手动加一
        var d = time.getDate(); // getDate方法从 Date 对象返回一个月中的某一天 (1 ~ 31)
        return y + "-" + M + "-" + d;
      } else {
        return "";
      }
    },
    selectGoods() {
      //FIXME 查询商品
      //请求axios，获取商品data
      //打开抽屉
      this.$axios({
        url: "/getProductsByClass",
        method: "get",
        params: {
          class_first: this.classForm.class_first,
          class_second: this.classForm.class_second,
        },
      }).then((res) => {
        console.log("this.goodsInfo", this.goodsInfo);
        this.drawerData = res.data.data;
        this.drawerVisible = true;
      });
    },
    pageChange(current) {
      this.currentPage = current;
      this.$axios({
        url: "/findDstAll",
        method: "get",
        params: {
          page: this.currentPage,
          num: this.pageSize,
        },
      }).then((res) => {
        this.tableData = res.data.data;
      });
    },
  },
  computed: {
    timeOn: function () {
      return this.tableData[0].onTime.toString();
    },
    timeOff: function () {
      return this.addForm.discountTime[1].toLocaleString();
    },
    isDiscount: function () {
      return (
        this.addForm.Discount_sort == "打折" ||
        this.editForm.Discount_sort == "打折"
      );
    },
    userId: function () {
      return this.$store.state.user.cardnumber;
    },
  },
  mounted() {
    this.$axios({
      url: "/findDstAll",
      method: "get",
      params: {
        page: this.currentPage,
        num: this.pageSize,
      },
    }).then((res) => {
      console.log("活动res：", res);
      this.tableData = res.data.data;
    });
    this.$axios({
      url: "/getClassAll",
      method: "get",
    }).then((res) => {
      console.log("class res:", res);
      this.classOptions = res.data.data;
    });
  },
};
</script>
<style lang="less" scoped>
#table,
#pagination {
  margin-top: 15px;
}
#codeArea {
  border: 1px solid;
  margin-top: 15px;
}
</style>